package com.example.smartgreenhouse.service.impl;

import com.example.smartgreenhouse.entity.FanHistoryStatus;
import com.example.smartgreenhouse.mapper.FanStatusMapper;
import com.example.smartgreenhouse.service.FanStatusService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class FanStatusServiceImpl implements FanStatusService {
    private final FanStatusMapper fanStatusMapper;

    @Override
    @Transactional
    public void insertFanStatus(Long fanId, Integer level, Boolean isAuto,Long greenhouseId) {
        FanHistoryStatus status = new FanHistoryStatus();
        status.setCurrentLevel(level);
        status.setIsAuto(isAuto);
        status.setGreenhouseId(greenhouseId);
        if (fanId != null) {
            status.setFanId(fanId);
        }
        
        fanStatusMapper.insert(status);
    }
}